﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading;
using LogService.DataAccessService;
using NLog;
using LogLevel = NLog.LogLevel;

namespace LogService
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    class ManagmentEndpoint: IManagementEndpoint
    {
        public void EstablishConnection()
        {
            LogManager.GetCurrentClassLogger().Info("Connection established");
            ClientEndpoint = OperationContext.Current.GetCallbackChannel<IClientEndpoint>();
        }

        public IClientEndpoint ClientEndpoint { get; private set; }
    }

    [ServiceContract(CallbackContract = typeof(IClientEndpoint))]
    interface IManagementEndpoint
    {
        [OperationContract(IsOneWay = true)]
        void EstablishConnection();
    }

    [ServiceContract]
    interface IClientEndpoint
    {
        [OperationContract(IsOneWay = true)]
        void SendLog(ManagmentLog log);
    }

    [DataContract]
    class ManagmentLog
    {
        [DataMember] public DateTime TimeStamp;
        [DataMember] public string LoggerName;
        [DataMember] public string Message;
        [DataMember] public string Level;
        [DataMember] public Guid Guid;
    }
}
